package com.sinosoft.hydra.um.domain.permission;

import com.alibaba.fastjson.annotation.JSONField;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * created:2014/12/03
 * <p>角色</p>
 * @author oujianlin@sinosoft.co
 */
@Entity
@DynamicInsert(true)
@DynamicUpdate(true)
@Table(name="UM_SYS_ROLE")
public class SysRole extends IdEntity implements java.io.Serializable {

	private String roleName;//角色名
	private String roleDesc;//角色描述
	private Integer available;//是否可用【0-不可用;1-可用】

	private Integer isTempRole;//是否为临时角色[0-否;1-是]
	private String removeTime;//定时删除临时角色corns

	private String jobId;
	
	private Integer orderNo;//排序

    private Date createDate;//创建时间

    @JSONField(serialize = false)
	private List<SysUserMember> sysUserMembers = new ArrayList<SysUserMember>();//用户集合
    @JSONField(serialize = false)
	private List<SysResource> sysResources = new ArrayList<SysResource>();//资源集合

    public SysRole() {
	}

	public SysRole(String id) {
		this.id = id;
	}

	/**
	 * 创建时间
	 * @return Date
	 */
	@Column(name="CREATE_DATE")
	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	
	/**
	 * 调度器id
	 * @return String
	 */
	@Column(name="JOB_ID")
	public String getJobId() {
		return jobId;
	}

	public void setJobId(String jobId) {
		this.jobId = jobId;
	}

	/**
	 * roleName
	 * @return String
	 */
	@Column(name="ROLE_NAME")
	public String getRoleName() {
		return this.roleName;
	}


	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}
	
	/**
	 * 角色描述
	 * @return String
	 */
	@Column(name="ROLE_DESC")
	public String getRoleDesc() {
		return this.roleDesc;
	}

	public void setRoleDesc(String roleDesc) {
		this.roleDesc = roleDesc;
	}

	/**
	 * 是否可用
	 * @return Integer
	 */
	@Column(name="AVAILABLE")
	public Integer getAvailable() {
		return this.available;
	}

	public void setAvailable(Integer available) {
		this.available = available;
	}
	
	/**
	 * 是否为临时角色
	 * @return String
	 */
	@Column(name="IS_TEMP_ROLE")
	public Integer getIsTempRole() {
		return this.isTempRole;
	}

	public void setIsTempRole(Integer isTempRole) {
		this.isTempRole = isTempRole;
	}
	
	/**
	 * 定时删除临时角色corns
	 * @return String
	 */
	@Column(name="REMOVE_TIME")
	public String getRemoveTime() {
		return this.removeTime;
	}

	public void setRemoveTime(String removeTime) {
		this.removeTime = removeTime;
	}
	
	/**
	 * 排序
	 * @return String
	 */
	@Column(name="ORDER_NO")
	public Integer getOrderNo() {
		return orderNo;
	}

	public void setOrderNo(Integer orderNo) {
		this.orderNo = orderNo;
	}

	/**
	 * 用户集合
	 * @return List<SysUserMember> 
	 */
	@ManyToMany(fetch=FetchType.LAZY)
	@JoinTable(name = "UM_SYS_ROLE_USER"	//中间表的表名
		, joinColumns = @JoinColumn(name = "ROLE_ID")	//指向本端的外键
		, inverseJoinColumns = @JoinColumn(name = "USER_ID"))	//指向对方端的外键
	public List<SysUserMember> getSysUserMembers() {
		return sysUserMembers;
	}

	public void setSysUserMembers(List<SysUserMember> sysUserMembers) {
		this.sysUserMembers = sysUserMembers;
	}
	
	/**
	 * 资源集合
	 * @return List<SysResource>
	 */
	@ManyToMany(fetch=FetchType.LAZY)
	@JoinTable(name = "UM_SYS_ROLE_RESOURCE"	//中间表的表名
		, joinColumns = @JoinColumn(name = "ROLE_ID")	//指向本端的外键
		, inverseJoinColumns = @JoinColumn(name = "RESOURCE_ID"))	//指向对方端的外键
	public List<SysResource> getSysResources() {
		return sysResources;
	}

	public void setSysResources(List<SysResource> sysResources) {
		this.sysResources = sysResources;
	}
}
